<template>
  <div v-loading="loading" class="list-table">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('预计现金流计算时点')" prop="valuationPoint">
              <dict-select
                v-model="form.valuationPoint"
                dictionary="valuation_point"
                :placeholder="$t('预计现金流计算时点')"
                :clearable="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('系统默认展示IRR时点')" prop="showPoint">
              <dict-select
                v-model="form.showPoint"
                dictionary="irr_show_type"
                :placeholder="$t('系统默认展示IRR时点')"
                :clearable="false"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <br>
        <br>
        <el-row>
          <div class="area-header">
            <span class="area-header-title">{{ $t('基金指标') }}</span>
          </div>
          <el-col :span="12">
            <el-form-item :label="$t('Gross IRR')" prop="fundGrossIrr">
              <dict-select
                v-model="form.fundGrossIrr"
                multiple
                dictionary="fund_irr_calculation_basis"
                :placeholder="$t('Gross IRR')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('Net IRR')" prop="fundNetIrr">
              <dict-select
                v-model="form.fundNetIrr"
                multiple
                dictionary="fund_irr_calculation_basis"
                :placeholder="$t('Net IRR')"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <br>
        <br>
        <el-row>
          <div class="area-header">
            <span class="area-header-title">{{ $t('项目指标') }}</span>
          </div>
          <el-col :span="12">
            <el-form-item :label="$t('IRR')" prop="dealIrr">
              <dict-select
                v-model="form.dealIrr"
                multiple
                dictionary="deal_cash_flow_type"
                :placeholder="$t('IRR')"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <br>
        <br>
        <el-row>
          <div class="area-header">
            <span class="area-header-title">{{ $t('出资人指标') }}</span>
          </div>
          <el-col :span="12">
            <el-form-item :label="$t('IRR')" prop="contributorIrr">
              <dict-select
                v-model="form.contributorIrr"
                multiple
                dictionary="lpbase_cashflow_business_type"
                :placeholder="$t('IRR')"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-row>
    </el-form>
    <br>
    <br>
    <div slot="footer" class="dialog-footer" style="text-align: center;">
      <!--保存 取消按钮-->
      <save-btn has-permi="fund:sysIndicatorsConfig" />
    </div>
  </div>
</template>

<script>
    import { saveSysIndicatorsConfig, getSysIndicatorsConfig } from '@/api/fund/sysIndicatorsConfig/sysIndicatorsConfig'
    export default {
        data() {
            return {
              // 查询参数
              queryParams: {
                pageNum: 1,
                pageSize: 10
              },
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                fundGrossIrr: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                fundNetIrr: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                dealIrr: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                contributorIrr: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ]
                }
            }
        },
        created() {
          this.init()
        },
        methods: {
            // 初始化数据
            init() {
              this.loading = true
              getSysIndicatorsConfig().then(response => {
                if (response.data) {
                  this.form = response.data
                }
                this.loading = false
              }).catch(() => {
                this.loading = false
              })
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    fundGrossIrr: undefined,
                    fundNetIrr: undefined,
                    dealIrr: undefined,
                    contributorIrr: undefined,
                    delFlag: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveSysIndicatorsConfig(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                }).catch(() => {
                    this.loading = false
                })
           }
        }
    }
</script>
